$(document).ready(function(){
	 var VAL ={
		        NORMAL     	 : "0000000"  ,
		        EVT_USER     : $("#userId").text(),
		        T_FBPINQOPE  : "FBPINQOPE"  ,
		        T_FBPTOOLOPE : "FBPTOOLOPE"  ,
		        T_FIPINQSHT  : "FIPINQSHT",
		        T_FBPBISOPE	 : 'FBPBISOPE',
		        T_FBPBISTOL  : 'FBPBISTOL',
		        T_FBPBOXMAG	 : 'FBPBOXMAG',
		        T_FBPBISPTH  : 'FBPBISPTH',
		        T_FIPINQBOX  : 'FIPINQBOX',
		        T_FPPMOVEIN	 : 'FPPMOVEIN',
		        T_HIPSHTHIS  : 'HIPSHTHIS',
		        T_FPPWKPOCLM : 'FPPWKPOCLM'
		    };
	 var domObj={
			 $prdHisDiv  	: $("#prdHisDiv"),
			 $prdHisListGrd : $("#prdHisListGrd"),
			 prdHisListPg   : "#prdHisListPg",
			 $prdPoiDiv 	: $("#prdPoiDiv"),
			 $prdPoiListGrd : $("#prdPoiListGrd"),
			 prdPoiListPg   : "#prdPoiListPg",
			 $boxIdTxt		: $("#boxIdTxt"),
			 buttons		: {
				 $query_btn  : $("#query_btn"),
				 $export_btn : $("#export_btn")
			 }
	 };
	 var iniGridInfo=function(){

   var prdHisInfoCM = [
       {name: 'evt_timestamp', index: 'evt_timestamp',   	label: START_DATETIME_TAG, 	    width: '200'},
       {name: 'evt_cate', 	   index: 'evt_cate',			label: EVT_CATE_TAG, 		    width: '180'},
       {name: 'prd_stat',      index: 'prd_stat',   	    label: PRD_STAT_TAG, 		    width: '180'},
       {name: 'tool_id_fk',    index: 'tool_id_fk',   		label: TOOL_ID_TAG, 		    width: '220'},
       {name: 'cr_ope_id_fk',  index: 'cr_ope_id_fk',     	label: CR_OPE_ID_TAG, 		    width: '180'},
       {name: 'cr_ope_dsc',    index: 'cr_ope_dsc',       	label: CR_OPE_DSC_TAG, 		    width: '180'},
       {name: 'nx_ope_id_fk',  index: 'nx_ope_id_fk',    	label: NX_OPE_ID_TAG, 		    width: '180'},
       {name: 'nx_ope_dsc',    index: 'nx_ope_dsc',   	    label: NX_OPE_DSC_TAG, 		    width: '180'},
       {name: 'wo_id_fk',      index: 'wo_id_fk',   		label: WO_ID_TAG, 			    width: '220'},
       {name: 'box_id_fk',     index: 'box_id_fk',   		label: BOX_ID_TAG, 		        width: '300'},
       {name: 'ship_box_id',   index: 'ship_box_id',        label: SHIP_BOX_ID_TAG, 	    width: '300'},
       {name: 'slot_no',       index: 'slot_no',   		    label: SLOT_NO_TAG, 		    width: '180'},
       {name: 'evt_usr',       index: 'evt_usr',   		    label: EVT_USR, 			    width: '180'}




       ];
       
/*       var prdPoiInfoCM = [
           {name: 'prd_seq_id_fk',      index: 'prd_seq_id_fk',   	label: SHEET_ID_TAG, 	width: '260'},
           {name: 'line_id',    		index: 'line_id',   		label: LINE_ID_TAG, 	width: '260'},
           {name: 'tool_id_fk',   		index: 'tool_id_fk',   		label: TOOL_ID_TAG, 	width: '260'},
           {name: 'unit_id', 			index: 'unit_id',			label: "Unit ID", 		width: '260'},
           {name: 'evt_usr', 			index: 'evt_usr',			label: EVT_USR, 		width: '260'},
           {name: 'evt_timestamp', 		index: 'evt_timestamp',		label: EVT_TIMESTAMP, 	width: '260'},
       ];*/
       
       domObj.$prdHisListGrd.jqGrid({
           url:"",
           datatype:"local",
           mtype:"POST",
           autowidth:true,
           shrinkToFit:true,
           scroll:false,
           rownumbers : true,
           resizable : true,
           loadonce:true,
           fixed:true,
           viewrecords:true,
           pager : domObj.prdHisListPg,
           colModel: prdHisInfoCM,
           onSelectRow: function(id){}
       });
       
/*       domObj.$prdPoiListGrd.jqGrid({
           url:"",
           datatype:"local",
           mtype:"POST",
           autowidth:true,
           shrinkToFit:true,
           scroll:true,
           rownumWidth : true,
           resizable : true,
           rowNum:40,
           loadonce:true,
           fixed:true,
           viewrecords:true,
           multiselect : true,
           pager : domObj.prdPoiListPg,
           colModel: prdPoiInfoCM,
           onSelectRow: function(id){}
       });*/
	};
	
	var clearInfo= function(){
		$("input").val("");
		domObj.$prdHisListGrd.jqGrid("clearGridData");
	};
	
	var btnFunc={
			query_func: function(prd_seq_id){
				if (!prd_seq_id) {
					showErrorDialog("","请输入屏体代码！");
					return;
				}
				var inObj = {
						trx_id : VAL.T_HIPSHTHIS,
						action_flg: 'T',
						prd_seq_id:prd_seq_id
				};
				var outObj = comTrxSubSendPostJson(inObj);
				if (outObj.rtn_code === VAL.NORMAL) {
					setGridInfo(outObj.oary_his,"#prdHisListGrd",true);
				}
/*				var inTrxObj = {
						trx_id : VAL.T_FPPWKPOCLM,
						action_flg: 'T',
						prd_seq_id_fk: prd_seq_id
				}
				var outTrxObj = comTrxSubSendPostJson(inTrxObj);
				if (outObj.rtn_code === VAL.NORMAL) {
					setGridInfo(outTrxObj.oary_pos,"#prdPoiListGrd",true);
				}*/
				
			}
	};
	
	
	
	var iniButtonAction=function(){
		domObj.buttons.$query_btn.click(function(){
			var prd_seq_id = domObj.$boxIdTxt.val();
			btnFunc.query_func(prd_seq_id);
		});
		domObj.buttons.$export_btn.click(function(){
			generateExcel("#prdHisListGrd");
		});
		domObj.$boxIdTxt.keydown(function(event){
			var prd_seq_id = domObj.$boxIdTxt.val();
			if (event.keyCode == 13) {
				btnFunc.query_func(prd_seq_id);
			}
		});
	};
	
	 var otherActionBind = function(){
        //Stop from auto commit
        $("form").submit(function(){
            return false;
        });
    };
	    
	var initializationFunc = function(){
		clearInfo();
		iniButtonAction();
		otherActionBind();
        iniGridInfo();
    };
	    
	var iniTransActionFunc =function(){
		(function ($) {
			$.getUrlParam = function (name) {
				var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
				var r = window.location.search.substr(1).match(reg);
				if (r != null) return unescape(r[2]); return null;
			}
		})(jQuery);
		
		var param = $.getUrlParam('prd_seq_id');
		if (param) {
			param = param.substring(1,(param.length-1));
			domObj.$boxIdTxt.val(param);
			btnFunc.query_func(param);
		}
	}

	    initializationFunc();
	    iniTransActionFunc();
    //enter
   /* document.onkeydown=function(event){
        var e = event || window.event || arguments.callee.caller.arguments[0];
        if(e && e.keyCode==13){ // 按 enter
            $('.bootbox').modal("hide");
        }
    }*/
    //表格自适应
    function resizeFnc() {
        var offsetBottom, divWidth,offsetBottom1, divWidth1;
        divWidth = $("#divTotal").width();
        offsetBottom =$(window).height() - $("#divTotal").offset().top;
        $("#divTotal").height(offsetBottom * 0.95);
        $("#prdHisListGrd").setGridWidth(divWidth * 0.99);
        $("#prdHisListGrd").setGridHeight(offsetBottom * 0.9 - 101);
        //2
/*        divWidth = $("#divTotal").width();
        offsetBottom = $(window).height() -   $("#divTotal").offset().top;
        $("#divTotal").height(offsetBottom * 0.70);
        $("#prdPoiListGrd").setGridWidth(divWidth * 0.95);
        $("#prdPoiListGrd").setGridHeight(offsetBottom * 0.40 - 51);*/

    };

    resizeFnc();
    $(window).resize(function () {
        resizeFnc();
    });
});